#include <cmath>
#include "Vector.hpp"

Vector::Vector(float x, float y)
	: x(x),
	  y(y)
{
}

Vector::Vector()
	: x(0.0f),
	  y(0.0f)
{
}

Vector Vector::operator-(const Vector& other) const
{
	Vector result;
	result.x = this->x - other.x;
	result.y = this->y - other.y;
	return result;
}

Vector Vector::operator+(const Vector& rhs) const
{
	return Vector(x+rhs.x, y+rhs.y);
}

void Vector::operator+=(const Vector& rhs)
{
	x += rhs.x;
	y += rhs.y;
}

Vector Vector::operator*(const float scalar) const
{
	return Vector(x*scalar, y*scalar);
}

void Vector::operator*=(const float scalar)
{
	x *= scalar;
	y *= scalar;
}

std::ostream& operator<<(std::ostream& o, const Vector& v)
{
	return o << "(" << v.x << ", " << v.y << ")";
}

float VecDotProduct(const Vector& lhs, const Vector& rhs)
{
	return lhs.x * rhs.x + lhs.y * rhs.y;
}

Vector VecNormalize(Vector& v)
{
	float magnitude = std::sqrt(std::pow(v.x, 2) + std::pow(v.y, 2));

	v.x = v.x/magnitude;
	v.y = v.y/magnitude;

	return v;
}

Vector VecNormalize(const Vector& v)
{
	Vector result(v);
	VecNormalize(result);
	return result;
}